#ifndef _2_66_H
#define _2_66_H

/**
 *  reference from
 *        http://lambda.cool/wiki/doku.php?id=answers:csapp:homework-2.66
 *
 *  Generate mask indicating leftmost 1 in x.Assume w=32.
 *  For example 0xFF00 -> 0x8000, and 0x6600 -->0x4000.
 *  if x = 0; then return 0;
 */
int leftmost_one(unsigned x){
    x |= x >> 1;
    x |= x >> 2;
    x |= x >> 4;
    x |= x >> 8;
    x |= x >> 16;

    return x - (x >> 1);
}


#endif // _2_66_H

